import { defineStore } from 'pinia';

export const useGridStore = defineStore("grid", {
  state: () => ({
    // Define your state properties here
    shard: 0,
    roomName: '',

    //是否启用random plan模式
    useRandomPlan: false,

    //random plan模式下，距离、临近道路数量、新的可用地块系数
    dc: 0,
    rc: 0,
    nc: 0,

    //每个loop的延时
    loopDelay: 0,
  }),
  getters: {
    // 获取三个系数组成的数组
    getThreeCoef(): number[] {
        return [this.dc, this.rc, this.nc];
    },

    // 获取延时
    getLoopDelay(): number {
        return this.loopDelay;
    },

    // 获取房间信息
    getRoomInfo():{shard: number, roomName: string} {
        return {shard: this.shard, roomName: this.roomName};
    }
  },
  actions: {

    updateCoef(coef: number[]) {
        this.dc = coef[0];
        this.rc = coef[1];
        this.nc = coef[2];
    },

    updateLoopDelay(delay: number) {
        this.loopDelay = delay;
    },

    updateRoomInfo(roomInfo: {shard: number, roomName: string}) {
        this.shard = roomInfo.shard;
        this.roomName = roomInfo.roomName;
        console.log(
          `room info updated in store: ${roomInfo.shard} ${roomInfo.roomName}`
        );
    },

    updateRandomPlanMode(mode: boolean) {
        this.useRandomPlan = mode;
    }
  }
});